package com.woniuxy.rbac.web;

import com.woniuxy.rbac.entity.Role;
import com.woniuxy.rbac.service.RoleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 角色Controller类
 *
 * @Auther: 老谭（<a href="http://www.woniuxy.com">蜗牛学苑</a>）
 */
@Controller
@RequestMapping("/role")
public class RoleController {
    private final static Logger logger = LoggerFactory.getLogger(RoleController.class);
    @Autowired
    private RoleService roleService;

    @GetMapping("/manage")
    public String add() {
        return "role/role_manage";
    }

    @PostMapping("/add")
    @ResponseBody
    public String add(Role role) {
        logger.debug("角色名:{},角色描述：{}", role.getName(), role.getDescription());
        roleService.add(role);
        return "ok";
    }

    @GetMapping("/getall")
    @ResponseBody
    public List<Role> getAll() {
        return roleService.getAll();
    }


}
